
module Kaminari

  module Helpers

    class Paginator

      def relevant_pages(options)
        options[:window] = (7-options[:current_page].to_i) if options[:current_page] < 5 && (options[:total_pages] >= 7)
        left_window_plus_one = 1.upto(options[:left] + 1).to_a
        right_window_plus_one = (options[:total_pages] - options[:right]).upto(options[:total_pages]).to_a
        inside_window_plus_each_sides = (options[:current_page] - options[:window] - 1).upto(options[:current_page] + options[:window] + 1).to_a

        (left_window_plus_one + inside_window_plus_each_sides + right_window_plus_one).uniq.sort.reject {|x| (x < 1) || (x > options[:total_pages])}
      end

    end

  end

end

